package com.example.myandroidtest.utils;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import java.util.Set;

/**
 * Created by Administrator on 2016/11/30.
 */
public class PrintUtils {


    /**
     * 打印太多的内容
     */
    public static void printMoreContent(String tag, String moreContent) {

        if (moreContent.length() > 4000) {
            int chunkCount = moreContent.length() / 4000;     // integer division
            for (int i = 0; i <= chunkCount; i++) {
                int max = 4000 * (i + 1);
                if (max >= moreContent.length()) {
                    L.i(tag, moreContent.substring(4000 * i));
                } else
                    L.i(tag, moreContent.substring(4000 * i, max));
            }
        } else
            L.i(tag, moreContent);
    }

    /**
     * 打印 Intent  log
     *
     * @param data
     */
    public static void printIntetnLog(Intent data) {
        L.e("intent   " + data.toString());
        if (data != null) {
            if (!TextUtils.isEmpty(data.getScheme()))
                L.e("scheme   " + data.getScheme());
            if (data.getData() != null)
                L.e("uri   " + data.getData().toString());
            if (data.getExtras() != null) {
                Bundle bundle = data.getExtras();
                Set<String> keySet = bundle.keySet();
                for (String key : keySet) {
                    Object o = bundle.get(key);
                    if (o != null) {
                        L.e(key + "   " + o.toString());
                    }
                }
            }
        }
    }

    /**
     * print 请求到的数据
     */
    public static void printRequestDataLog(String value) {
        try {
            L.e("print", value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
